var is_loading = !1,
  utils = getApp().helper;

Page({
  data: {
    order_id: null,
    order_type: null,
    order_info: [],
    latitude: '',
    longitude: '',
    hide: 1,
    qrcode: ''
  },
  onLoad: function (t) {
    getApp().page.onLoad(this, t);
    if (!t.order_id && t.scene) {
      var s = decodeURIComponent(t.scene);
      if (void 0 !== s) {
        var a = utils.scene_decode(s);
        this.setData({
          order_id: a.order_id,
          order_type: a.order_type
        });
        a.order_id && (this.wancheng(a.order_id));
        return;
      }
    }
    this.setData({
      order_id: t.order_id,
      order_type: t.order_type
    });
    console.log(this.data.order_id);
    this.getLocation()
    // this.loadData();
  },
  loadData: function () {
    let o = this;
    console.log(o.data);
    getApp().core.showLoading()
    getApp().request({
      url: getApp().api.order.de_detail,
      data: {
        order_id: o.data.order_id,
        delivery_type: o.data.order_type,
        latitude: o.data.latitude,
        longitude: o.data.longitude
      },
      method: "get",
      success: function (a) {
        getApp().core.hideLoading()
        if (0 == a.code) {
          o.setData({
            order_info: a.data
          });
          console.log(o.data.order_info)
        } else getApp().core.showToast({
          title: a.msg,
          icon: 'none'
        });
      },
      fale: function (t) {
        getApp().core.hideLoading()
      }
    });
  },
  takeGoods: function (y) {
    var th = this;
    getApp().request({
      url: getApp().api.order.peisong,
      data: {
        oid: y.target.dataset.oid,
        status: y.target.dataset.status,
        delivery_type: y.target.dataset.order_type,
      },
      success: function (t) {
        if (t.code == 0) {

          getApp().core.showModal({
            title: "取货成功",
            content: "恭喜，快去配送吧~",
            showCancel: !1,
            success: function (a) {
              a.confirm && th.loadData();
            }
          });
        } else {
          getApp().core.showModal({
            title: "取货失败",
            content: t.errorMsg,
            showCancel: !1,
            success: function (a) {
              a.confirm && th.loadData();
            }
          });
        }
      }
    })
  },
  wancheng: function (order_id) {
    var a = this;
    getApp().request({
      url: getApp().api.order.delivery_order_confirm,
      data: {
        order_id: order_id,
        status: 3,
        delivery_type: a.data.delivery_type
      },
      success: function (t) {
        wx.showModal({
          title: '订单收货',
          content: t.msg,
          showCancel: false, //是否显示取消按钮
          confirmText: "确定", //默认是“确定”
          // confirmColor: 'skyblue', //确定文字的颜色
          success: function (res) {
            //点击确定
            wx.redirectTo({
              url: t.data,
            });
          }
        })
      }
    })
  },
  getLocation: function () {
    let o = this;
    wx.getLocation({
      type: 'wgs84',
      success: (res) => {
        o.setData({
          latitude: res.latitude,
          longitude: res.longitude
        });
      },
      complete: function () {
        o.loadData();
      }

    })
  },
  telShop: function (e) {
    console.log(e);
    var phone = e.currentTarget.dataset.phone;
    if (phone) {
      wx.makePhoneCall({
        phoneNumber: phone
      })
    } else {
      getApp().core.showModal({
        title: "拨打失败",
        content: "商家未绑定手机号",
        showCancel: !1
      });
    }
    console.log(e);
  },
  orderQrcode: function (a) {
    var o = this,
      order_id = a.target.dataset.oid,
      delivery_type = a.target.dataset.order_type;

    getApp().core.showModal({
      title: "提示",
      content: "确认收货方式",
      cancelText: "二维码",
      confirmText: "确认到家",
      success: function (t) {
        t.cancel && (
          wx.showLoading({
            title: "正在加载",
            mask: !0
          }), getApp().request({
            url: getApp().api.user.get_delivery_qrcode,
            data: {
              order_id: order_id,
              delivery_type: delivery_type
            },
            success: function (t) {
              0 == t.code ? o.setData({
                hide: 0,
                qrcode: t.data.url
              }) : wx.showModal({
                title: "提示",
                content: t.msg
              });
            },
            complete: function () {
              wx.hideLoading();
            }
          })
        );
        t.confirm && (getApp().core.showLoading({
          title: "操作中"
        }), getApp().request({
          url: getApp().api.order.delivery_order_confirm,
          data: {
            order_id: order_id,
            delivery_type: delivery_type,
            type: 1
          },
          success: function (t) {
            getApp().core.hideLoading(), getApp().core.showToast({
              title: t.msg,
              success: function (e) {
                console.log('drtedgrg');
                setTimeout(function(){
                  getApp().core.navigateTo({
                    url: '/delivery/task_hall/task_hall'
                  })
                },1000);
              }
            });
          }
        }));
      }
    });
  },
  goLocation: function (a) {
    console.log(a);
    var o = this,
      longitude = a.currentTarget.dataset.longitude,
      latitude = a.currentTarget.dataset.latitude,
      address = a.currentTarget.dataset.address;
    console.log(parseFloat(longitude));
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        wx.openLocation({ //​使用微信内置地图查看位置。
          latitude: parseFloat(latitude), //要去的纬度-地址
          longitude: parseFloat(longitude), //要去的经度-地址
          scale: 18,
          address: address
        })
      }
    })
  },
  hide: function (t) {
    this.setData({
      hide: 1
    });
  },
})